﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Common.Enums.Archives;
using S.EarTag.Read.API.Application.MediatorCommand.ProductionGradingCommand;

namespace S.EarTag.Read.API.Controllers
{
    /// <summary>
    /// 生产定级——(读)
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductionGradingController : ControllerBase
    {
        private readonly IMediator _mediator;
        public ProductionGradingController(IMediator mediator)
        {
            _mediator= mediator;
        }
        /// <summary>
        /// 条件查询显示生产定级列表
        /// </summary>
        /// <param name="FileType"></param>
        /// <param name="RankEarTag"></param>
        /// <param name="Current"></param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<IActionResult> GetProductionGradingListPage(int pageIndex,int pageSize, int FileType, string? RankEarTag, int Current)
        {
            ProductionGradingSeachCommand command = new ProductionGradingSeachCommand();
            command.SheepType = (int)FileType;
            command.RankEarTag = RankEarTag;
            command.Current = Current;
            command.pageIndex=pageIndex;
            command.pageSize=pageSize;
            var list = await _mediator.Send(command);
            return Ok(list);
        }
        /// <summary>
        /// 根据Id查询反填生产定级信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<IActionResult> GetByIdProductionGrading(string? EarTag)
        {
            ProductionGradingByIdCommand command= new ProductionGradingByIdCommand();
            command.RankEarTag = EarTag;
            var result = await _mediator.Send(command);
            return Ok(result);
        }
    }
}
